package com.activenetwork.util.datepicker;

import java.util.Calendar;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.activenetwork.util.PageLoader;

public class DatePicker {
	private WebElement dateDropdown;

	public DatePicker(WebElement dateField){
	    dateDropdown = dateField.findElement(By.xpath("./following-sibling::span[@class='add-on nexus-date-dropdown']"));
	}
	

	public void pick(Calendar calendar){
		dateDropdown.click();
		
		int targetYear = calendar.get(Calendar.YEAR);
		int targetMonth = calendar.get(Calendar.MONTH);
		int targetDate = calendar.get(Calendar.DATE);
		
		CalendarDateDiv dateDiv = PageLoader.load(CalendarDateDiv.class);
		CalendarMonthDiv monthDiv = dateDiv.switchMonth();
		CalendarYearDiv yearDiv = monthDiv.switchYear();
		
		// select year
		monthDiv = yearDiv.pick(targetYear);
		// select month
		dateDiv = monthDiv.pick(targetMonth);
		// select date
		dateDiv.pick(targetDate);
	}
	
	

}
